package JZ28_数组中出现次数超过一半的数字;

public class Solution {
    public int MoreThanHalfNum_Solution(int [] array) {
        int count = 0;
        int number = 0;

        for (int n : array){
            if (count == 0){
                count = 1;
                number = n;
            }else {
                if (n == number){
                    count++;
                }else {
                    count--;
                }
            }
        }
        return number;
    }
}